<template>
  <a-config-provider :locale="locale">
    <router-view/>
  </a-config-provider>
</template>

<script>
import zh_CN from 'ele-admin-pro/packages/lang/zh_CN';
import zh_TW from 'ele-admin-pro/packages/lang/zh_TW';
import en from 'ele-admin-pro/packages/lang/en_US';
import store from '@/store';

const languages = {zh_CN, zh_TW, en};

export default {
  data() {
    return {
      locale: languages[this.$i18n.locale]
    };
  },
  mounted() {
    // 获取后台主题信息
    store.dispatch('system/loadThemeInfo').then(result => {
      let faviconUrl = result.gunsMgrFavicon;
      this.$nextTick(() => {
        let link = document.querySelector('link[rel*=\'icon\']') || document.createElement('link');
        link.type = 'image/x-icon';
        link.rel = 'shortcut icon';
        link.href = faviconUrl;
        document.getElementsByTagName('head')[0].appendChild(link);
      });
    });
  },
  computed: {
    language() {
      return this.$i18n.locale;
    }
  },
  watch: {
    language() {
      this.locale = languages[this.language];
    }
  }
};
</script>
